<template>
  <page-header-wrapper>
    <global-search :list="searchList" @search="handleSearch" @reset="handleReset"> </global-search>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <template #tabAction>
          <!-- <y-button v-if="editDisabled" type="primary" icon="plus" @click="handleAdd">新建楼盘</y-button> -->
        </template>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <ellipsis :length="32" slot="ellipsis" slot-scope="text">{{ text || '/' }}</ellipsis>
        <div slot="action" slot-scope="text, record">
          <a-popover placement="left" :overlayStyle="{ width: '50%' }">
            <template slot="content">
              <a-descriptions title="楼盘详情" :column="2" size="small" bordered>
                <a-descriptions-item label="项目名称"> {{ record.XMNAME }}</a-descriptions-item>
                <a-descriptions-item label="项目状态">{{ record.Mode }}</a-descriptions-item>
                <a-descriptions-item label="楼盘名称"> {{ record.Name }} </a-descriptions-item>
                <a-descriptions-item label="总面积"> {{ record.TotalArea }}m² </a-descriptions-item>
                <a-descriptions-item label="楼盘地址"> {{ record.Address }} </a-descriptions-item>
              </a-descriptions>
            </template>
            <y-button type="link">查看</y-button>
          </a-popover>
          <!-- <y-button type="link" v-if="editDisabled" class="text-warning" @click="handleEdit(record)">修改</y-button> -->
        </div>
        <y-button
          slot="ckfy"
          slot-scope="text, record"
          class="text-success"
          type="link"
          size="small"
          @click="handleHouse(record)"
          >查看房源信息</y-button
        >
        <!-- <y-button slot="ckxq" class="text-warning" type="link" size="small">查看小区详情</y-button> -->
      </s-table>
    </a-card>
    <realEstateForm :visible.sync="visibleForm" :data.sync="editData" @success="tableRefresh" />
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import realEstateForm from './components/form.vue'
import { getRealEstateInformationList } from '@/api/followUpManagement'
export default {
  components: {
    STable,
    Ellipsis,
    realEstateForm,
  },
  data() {
    return {
      visibleForm: false,
      editData: {},
      queryParam: {
        Userid: this.$store.getters.userid,
        strContent: {},
      },
      searchList: [
        {
          label: '楼盘名称',
          fields: 'Name',
          type: 'input',
          props: {
            placeholder: '请输入楼盘名称',
          },
        },
      ],
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'XMNAME',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '楼盘名称',
          align: 'center',
          dataIndex: 'Name',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '详细地址',
          align: 'center',
          dataIndex: 'Address',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '总面积',
          align: 'center',
          dataIndex: 'TotalArea',
          customRender: (text) => `${text}㎡`,
        },
        {
          title: '查看房源',
          align: 'center',
          scopedSlots: { customRender: 'ckfy' },
        },
        // {
        //   title: '查看小区',
        //   align: 'center',
        //   scopedSlots: { customRender: 'ckxq' }
        // },
        {
          title: '操作',
          align: 'center',
          width: '120px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        this.selectedRowKeys = []
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getRealEstateInformationList(requestParameters).then((res) => res)
      },
    }
  },
  computed: {
    editDisabled() {
      console.log('this.$store.state.roleid', this.$store.state.user.roleid)
      return this.$store.state.user.roleid.split(',').includes('41')
    },
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.tableRefresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.tableRefresh(true)
    },
    tableRefresh(refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleAdd() {
      this.editData = {}
      this.visibleForm = true
    },
    handleEdit(record) {
      this.editData = record
      this.visibleForm = true
    },
    handleDetail(record) {
      this.editData = record
      this.visibleDetail = true
    },
    handleHouse(e) {
      this.$router.push({
        name: 'realEstateInformationHouseCheck',
        params: {
          id: e.ID,
        },
        query: {
          name: e.Name,
          address: e.Address,
        },
      })
    },
  },
}
</script>
<style scoped></style>
